package com.example.dingtalkwebproject.utils;

import java.security.MessageDigest;

public class getMD5Password {

    public static String customizedMD5(String text) {
        try {
            // 1. 将明文转为大写并进行 UTF-8 编码
            byte[] textBytes = text.toUpperCase().getBytes("UTF-8");

            // 2. 计算 MD5 哈希
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(textBytes);
            byte[] digest = md.digest();

            // 3. 获取 MD5 结果并全部转换为大写
            StringBuilder md5ResultUpper = new StringBuilder();
            for (byte b : digest) {
                md5ResultUpper.append(String.format("%02X", b));
            }

            return md5ResultUpper.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
